/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cms.action.adminaction;

import cms.sessionbean.ConferenceItemApplicationRemote;
import cms.sessionbean.PaymentMgmtRemote;
import cms.util.EjbLocator;
import com.opensymphony.xwork2.ActionContext;
import dto.Conferenceitem;
import dto.ConferenceitemId;
import dto.Itemauthors;
import dto.ItemauthorsId;
import dto.Payment;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import model.AuthorModel;
import model.ConferenceListDisplayModel;
import model.ConferenceModel;
import model.ModelConverter;
import model.PaymentModel;

/**
 *
 * @author Timmy
 */
public class AdminConferItemAction {
    private String conferenceName;
    private String itemName; 
    private List<Conferenceitem> items;
    private List<ConferenceListDisplayModel> displayItems; 
    private List<AuthorModel> authorModel;
    private ConferenceListDisplayModel oneItem; 
    private String redirectURL ;
    private List<PaymentModel> paymentModels;
    
    private String PayUserName;
    private String PayName;

    public String getPayUserName() {
        return PayUserName;
    }

    public void setPayUserName(String PayUserName) {
        this.PayUserName = PayUserName;
    }

    public String getPayName() {
        return PayName;
    }

    public void setPayName(String PayName) {
        this.PayName = PayName;
    }

    public Integer getPayType() {
        return PayType;
    }

    public void setPayType(Integer PayType) {
        this.PayType = PayType;
    }

    public Integer getPayStatus() {
        return PayStatus;
    }

    public void setPayStatus(Integer PayStatus) {
        this.PayStatus = PayStatus;
    }
    private Integer PayType;
    private Integer PayStatus;


    public List<PaymentModel> getPaymentModels() {
        return paymentModels;
    }

    public void setPaymentModels(List<PaymentModel> paymentModels) {
        this.paymentModels = paymentModels;
    }

    public String getRedirectURL() {
        return redirectURL;
    }

    public void setRedirectURL(String redirectURL) {
        this.redirectURL = redirectURL;
    }

    public ConferenceListDisplayModel getOneItem() {
        return oneItem;
    }

    public void setOneItem(ConferenceListDisplayModel oneItem) {
        this.oneItem = oneItem;
    }
    
    
    public String getItemName() {
        return itemName;
    }

    public void setItemName(String itemName) {
        this.itemName = itemName;
    }

    public List<AuthorModel> getAuthorModel() {
        return authorModel;
    }

    public void setAuthorModel(List<AuthorModel> authorModel) {
        this.authorModel = authorModel;
    }

    
    
    public List<ConferenceListDisplayModel> getDisplayItems() {
        return displayItems;
    }

    public void setDisplayItems(List<ConferenceListDisplayModel> displayItems) {
        this.displayItems = displayItems;
    }

    public List<Conferenceitem> getItems() {
        return items;
    }

    public void setItems(List<Conferenceitem> items) {
        this.items = items;
    }

    public String getConferenceName() {
        return conferenceName;
    }

    public void setConferenceName(String conferenceName) {
        this.conferenceName = conferenceName;
    }
    
    
    public AdminConferItemAction() {
    }
    
    public String execute() throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    public String list()
    {
         ConferenceItemApplicationRemote cb = (ConferenceItemApplicationRemote)EjbLocator.getInstance().LookUpBeanByName(ConferenceItemApplicationRemote.class, "ConferenceItemApplication");
         items=cb.getConfercenItemsByConferenceName(conferenceName);
//        ConferenceitemId id  = new ConferenceitemId(this.conferenceName,"Item1");
//        items.add(new Conferenceitem(id,"Item Desc 1",1,"sb.html",1,(double)10,false));
//        id  = new ConferenceitemId(this.conferenceName,"Item2");
//        items.add(new Conferenceitem(id,"Item Desc 2",2,"sb.html",2,(double)20,false));
//        id  = new ConferenceitemId(this.conferenceName,"Item3");
//        items.add(new Conferenceitem(id,"Item Desc 3",3,"sb.html",3,(double)30,false));
        
        displayItems = ConferenceModel.ConverModelList(items);
        return "itemlist";
    }
    
    public String processModify()
    {
        ConferenceItemApplicationRemote cb = (ConferenceItemApplicationRemote)EjbLocator.getInstance().LookUpBeanByName(ConferenceItemApplicationRemote.class, "ConferenceItemApplication");
        Conferenceitem item =  cb.getConferenceItem(conferenceName, itemName);
        item.setItemDescription(oneItem.getItemDescription());
        item.setCategory(ConferenceModel.GetConferenceItemValue(oneItem.getCategory()));
        item.setSellPrice(Double.parseDouble(oneItem.getSellPrice()));
        item.setIsBlindReivew("True".equals(oneItem.getIsBlindReview()));
        cb.updateConferenceItem(item);
        
        this.redirectURL = "list_"+this.conferenceName;
        return "updatesuccess";
    }
    
    public String modify()
    {
        ConferenceItemApplicationRemote cb = (ConferenceItemApplicationRemote)EjbLocator.getInstance().LookUpBeanByName(ConferenceItemApplicationRemote.class, "ConferenceItemApplication");
         Conferenceitem item =  cb.getConferenceItem(conferenceName, itemName);
         oneItem = ConferenceModel.ConverModel(item);
//        oneItem = new ConferenceListDisplayModel();
//        oneItem.setCategory("Workshop");
//        oneItem.setConferenceName(this.conferenceName);
//        oneItem.setFilePath("SB.html");
//        oneItem.setIsBlindReview("False");
//        oneItem.setItemDescription("SB");
//        oneItem.setItemName(this.itemName);
//        oneItem.setSellPrice("300.15");
//        oneItem.setStatus("Not Assigned");
        return "itemDetail";
    }
    
    public String showAuthor()
    {
       ConferenceItemApplicationRemote cb = (ConferenceItemApplicationRemote)EjbLocator.getInstance().LookUpBeanByName(ConferenceItemApplicationRemote.class, "ConferenceItemApplication");
      List<Itemauthors> authors= cb.getItemAuthors(conferenceName, itemName);
//        List<Itemauthors> authors = new ArrayList<Itemauthors>();
//        ItemauthorsId id = new ItemauthorsId("sb","sb","sb");
//        Itemauthors author = new Itemauthors(id,true);
//        authors.add(author);  
//        
//        id = new ItemauthorsId("sb1","sb","sb");
//        author = new Itemauthors(id,false);
//        authors.add(author);   
//        
//        id = new ItemauthorsId("sb2","sb","sb");
//        author = new Itemauthors(id,false);
//        authors.add(author); 
        
        authorModel = ConferenceModel.ConverAuthorModelList(authors);
        return "authorList";
    }
    
    public String pay()
    {
        PaymentMgmtRemote cb =(PaymentMgmtRemote) EjbLocator.getInstance().LookUpBeanByName(PaymentMgmtRemote.class,"PaymentMgmt");
        List<Payment> paymentList = cb.getAllItemPayments(itemName);
        this.paymentModels = ModelConverter.ConvertPaymentList(paymentList);
        return "payList";
    }
    
    public String ChangeStatus()
    {
        PaymentMgmtRemote cb =(PaymentMgmtRemote) EjbLocator.getInstance().LookUpBeanByName(PaymentMgmtRemote.class,"PaymentMgmt");
        Payment pay =  cb.getPayment(PayUserName, PayName, PayType);
       pay.setPayStatus(PayStatus);
       pay.setApproveDate(new Date());
       pay.setApprover(ActionContext.getContext().getSession().get("adminName").toString());
       cb.updatePayment(pay);
        this.redirectURL = "list_"+ this.conferenceName;
          return "updatesuccess";
    }
}
